<%@ Register TagPrefix="dammela" Namespace="whole" Assembly = "dammela" %>
<%@ Page Language="C#" Description="Homepage" debug="false" EnableViewState="false"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Drawing"%>
<%@ Import Namespace="System.Drawing.Imaging"%>

<html>
<head>
<LINK type="text/css" rel="stylesheet" href="/main.css">
<meta http-equiv="Content-Type" Content="text/html; charset=UTF-8">
<title id="title" runat=server></title>
<dammela:scripts ID="Scripts1" runat="server"/></head>

<script language="C#" runat=server>

void Page_Load(Object sender, EventArgs EvArgs) {
	HttpRequest req = Page.Request;
	NameValueCollection getColl	=	req.QueryString;
	NameValueCollection formColl	=	req.Form;

	string picname = "";

	int activityId = -1;
	if( Convert.ToInt32( getColl.Get("activityId") ) > 0 )
		activityId = Convert.ToInt32( getColl.Get("activityId") );

	if( activityId <= 0 )
		return;

	for (int i=0; i<Request.Files.Count; i++ )
	{
		string strSrc = Request.Files[i].FileName;
		string ext = Path.GetExtension(strSrc);
		picname = activityId.ToString( "x" );
		string splashDst = Request.MapPath( "\\imgs\\gallery\\splash\\" + picname );
		string thumbDst = Request.MapPath( "\\imgs\\gallery\\thumb\\" + picname );

		if( ext.ToUpper() != ".GIF" && ext.ToUpper() != ".JPG" )
			Page.Response.Redirect( "/help/showError.aspx?error=342" );

		if( Request.Files[i].ContentLength > (30*1024) )
			Page.Response.Redirect( "/help/showError.aspx?error=343" );

		for(int k=1; File.Exists( splashDst ); k++ )
				splashDst = Request.MapPath( "\\imgs\\gallery\\splash\\" + picname + k.ToString() );
		for(int k=1; File.Exists( thumbDst ); k++ )
				thumbDst = Request.MapPath( "\\imgs\\gallery\\splash\\" + picname + k.ToString() );

//		HttpPostedFile postedFile = Request.Files[i];
//		Request.Files[i].SaveAs( strDst );

		Bitmap gBitmap = new Bitmap( Request.Files[i].InputStream );

		int h = gBitmap.Height;
		int w = gBitmap.Width;

		if( w > 120 ) {
			h = h*120/w;
			w = 120;
		}else if( h > 90 ) {
			w = w*90/h;
			h = 90;
		}

		System.Drawing.Image gThumbnail = gBitmap.GetThumbnailImage(
				w, h, null, IntPtr.Zero);

		splashDst = splashDst + ".jpg";
		thumbDst 	= thumbDst + ".jpg";

		gBitmap.Save( splashDst, System.Drawing.Imaging.ImageFormat.Jpeg );
		gThumbnail.Save( thumbDst, System.Drawing.Imaging.ImageFormat.Jpeg );

		body.InnerHtml = Request.Url.ToString()
			+"<br/>"+splashDst
			+"<br/>"+"width="+gBitmap.Width.ToString()+"height="+gBitmap.Height.ToString()
			+"<br/>"+thumbDst
			+"<br/>"+"width="+w.ToString()+"height="+h.ToString()
			;
	}
}
</script>
<body background="/imgs/tile_mucca.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<div class="Pbox" width="100%">
<dammela:menuBanner runat="server"/>
</div>
<table class="body" border="0" cellspacing="10" cellpadding="0">
<tr><td valign="top" width="150px">

<table border="0" cellspacing="0" cellpadding="0" width="150px">
<tr><td valign="top">
<dammela:login ID="Login1" 
    xml="/login/login.xml"
    xsl="/login/login.xsl"
    kind="FREAKMEUP"
    runat="server"/> 
<img height="10" src="/imgs/spacer.gif"/>
<dammela:cerca look="HOME" runat=server/>
</td></tr>
<tr><td height="10px"></td></tr>
<tr><td align="center"><asp:Xml id="xml1" DocumentSource="/help/ad1.xml" TransformSource="/help/ad1.xsl" runat="server"/></td></tr>
</table>

</td>
<td valign="top" align="left">
<%= Request.Url.LocalPath.ToUpper()%>
<br/>
<%= Path.GetTempFileName()%>
<br/>
			<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="">
			<b>Carica la foto!</b>
			<p/>
			<INPUT TYPE="FILE" SIZE="20" NAME="FILE1"></INPUT>
			<p/>
			<INPUT TYPE="SUBMIT" VALUE="Invia la foto!"></INPUT>
			<p/>
			<span class="body_10px_red">Non sono ammesse foto pornografiche o fasulle!<p/>Gli unici formati supportati sono Gif e Jpg,<br/>e la dimensione non deve superare i 30KByte.</span>
			<p/>
			</FORM>

<p/>
<span id="body" runat=server/>
<p/>
<dammela:gallery kind="LOADPICS" runat=server/>
</td>
</tr>

</table>
<div style="width:100%;">
<dammela:footer runat="server"/>
</div>
</body>
</html>